import { GameMgr } from "./GameMgr"
import Utils from "./GameUtils"
import { SmallHandler } from "./handler/SmallHandler"
import { BigHandler } from "./handler/BigHandler"
import { Player } from "./core/Player"
import { 幽灵Handler } from "./handler/幽灵Handler"
import { 炮台Handler } from "./handler/炮台Handler"
import { 恶灵Handler } from "./handler/恶灵Handler"
import { 狙炮Handler } from "./handler/狙炮Handler"
import { 顽石Handler } from "./handler/顽石Handler"
import { 地灵Handler } from "./handler/地灵Handler"
import { 精灵Handler } from "./handler/精灵Handler"
import { 沙兵Handler } from "./handler/沙兵Handler"
import { 沙皇Handler } from "./handler/沙皇Handler"
import { 野猪Handler } from "./handler/野猪Handler"
import { 野马Handler } from "./handler/野马Handler"
import { 拳师Handler } from "./handler/拳师Handler"
import { 灵阵Handler } from "./handler/灵阵Handler"
import { 天谕Handler } from "./handler/天谕Handler"
import { 妖术Handler } from "./handler/妖术Handler"
import { 鼓舞Handler } from "./handler/鼓舞Handler"


/**
 * 对局对战类
 */
export class HandlerMgr{
    
    gameMgr:GameMgr
    smallHandler:SmallHandler
    bigHandler:BigHandler
    handler_幽灵:幽灵Handler
    handler_恶灵:恶灵Handler
    handler_炮台:炮台Handler
    handler_狙炮:狙炮Handler
    handler_顽石:顽石Handler
    handler_地灵:地灵Handler
    handler_精灵:精灵Handler
    handler_沙兵:沙兵Handler
    handler_沙皇:沙皇Handler
    handler_野猪:野猪Handler
    handler_野马:野马Handler
    handler_拳师:拳师Handler
    handler_灵阵:灵阵Handler
    handler_天谕:天谕Handler
    handler_妖术:妖术Handler
    handler_鼓舞:鼓舞Handler

    constructor(gameMgr:GameMgr){
        this.gameMgr = gameMgr
        this.smallHandler = new SmallHandler(gameMgr,this)
        this.bigHandler = new BigHandler(gameMgr,this)
        this.handler_幽灵 = new 幽灵Handler(gameMgr,this)
        this.handler_恶灵 = new 恶灵Handler(gameMgr,this)
        this.handler_炮台 = new 炮台Handler(gameMgr,this)
        this.handler_狙炮 = new 狙炮Handler(gameMgr,this)
        this.handler_顽石 = new 顽石Handler(gameMgr,this)
        this.handler_地灵 = new 地灵Handler(gameMgr,this)
        this.handler_精灵 = new 精灵Handler(gameMgr,this)
        this.handler_沙兵 = new 沙兵Handler(gameMgr,this)
        this.handler_沙皇 = new 沙皇Handler(gameMgr,this)
        this.handler_野猪 = new 野猪Handler(gameMgr,this)
        this.handler_野马 = new 野马Handler(gameMgr,this)
        this.handler_拳师 = new 拳师Handler(gameMgr,this)
        this.handler_灵阵 = new 灵阵Handler(gameMgr,this)
        this.handler_天谕 = new 天谕Handler(gameMgr,this)
        this.handler_妖术 = new 妖术Handler(gameMgr,this)
        this.handler_鼓舞 = new 鼓舞Handler(gameMgr,this)
    }

    gc() {
        this.gameMgr = null
        this.smallHandler.gc()
        this.bigHandler.gc()
        this.handler_幽灵.gc()
        this.handler_恶灵.gc()
        this.handler_炮台.gc()
        this.handler_狙炮.gc()
        this.handler_顽石.gc()
        this.handler_地灵.gc()
        this.handler_精灵.gc()
        this.handler_沙兵.gc()
        this.handler_沙皇.gc()
        this.handler_野猪.gc()
        this.handler_野马.gc()
        this.handler_拳师.gc()
        this.handler_灵阵.gc()
        this.handler_天谕.gc()
        this.handler_妖术.gc()
        this.handler_鼓舞.gc()
        this.smallHandler = null
        this.bigHandler = null 
        this.handler_幽灵 = null
        this.handler_恶灵 = null
        this.handler_炮台 = null
        this.handler_狙炮 = null
        this.handler_顽石 = null
        this.handler_地灵 = null
        this.handler_精灵 = null
        this.handler_沙兵 = null
        this.handler_沙皇 = null
        this.handler_野猪 = null
        this.handler_野马 = null
        this.handler_拳师 = null
        this.handler_灵阵 = null
        this.handler_天谕 = null
        this.handler_妖术 = null
        this.handler_鼓舞 = null
    }

    /** 客户端弹出Toast，一般是行动失败 */
    showToast(player:Player,message:string) {
        player.user.sendObj(Utils.getObj("showToast",{"message":message}))
    }

    /** 行动力消耗 */
    spendAction(player:Player,action:number) {
        player.small.changeEnergy(-action)
    }
}